package offer.secnod;

import javax.swing.plaf.basic.BasicArrowButton;

public class Offer21 {

//    public void reOrderArray(int [] array){
//        int left=0;
//        int  right=array.length-1;
//        while (left<=right){
////            if ((array[left]&1)==1&&(array[right]&1)!=1){
////                left++;
////                right--;
////            }else {
////                if ((array[left]&1)!=1&&(array[right]&1)!=1){
////
////
////                }
////
////
////            }
//            while ((array[left]&1)==1){
//                left++;
//            }
//            while ((array[right]&1)!=1){
//                right++;
//            }
//            if (left>right){
//                return;
//            }
//            int temp=array[left-1];
//            array[left-1]= array[right+1];
//            array[right+1]=temp;
//
//        }
//    }


    public int[] exchange(int[] array) {
        int left=0;
        int  right=array.length-1;
        while (left<=right){
            while (left<= array.length-1&&(array[left]&1)==1){
                left++;
            }
            while (right>=0&&(array[right]&1)!=1){
                right--;
            }
            if (left>right){
                return array;
            }
            int temp=array[left];
            array[left]= array[right];
            array[right]=temp;
            left++;
            right--;

        }
        return array;
    }

    public static void main(String[] args) {
        Offer21 offer21 = new Offer21();
        int[] arr={1,3,5};
        int[] exchange = offer21.exchange(arr);
        for (int a :
                exchange) {
            System.out.println(a);

        }
    }
}
